<HTML><HEAD><TITLE>get_file_info(+File, ?Attr, -Value)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Operating System</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>get_file_info(+File, ?Attr, -Value)</H1>
Succeeds if the file File (with absolute or relative pathname) exists and
the value of its attribute Attr unfies with Value.


<DL>
<DT><EM>File</EM></DT>
<DD>Atom or string.
</DD>
<DT><EM>Attr</EM></DT>
<DD>Atom or variable.
</DD>
<DT><EM>Value</EM></DT>
<DD>Constant or variable.
</DD>
</DL>
<H2>Description</H2>
   This predicate is used to test the properties of a specified file, it
   allows to examine the values obtained from the stat(2) system call.
   Attr specifies one of the attributes listed below or a variable, on
   return, Value is unified with the attribute value.

<P>
   The possible attributes and their meanings are:

<P>
<PRE>
    Attribute  Meaning
   ----------------------------------
    mode       file mode; see
               values below
    inode      inode number
    nlink      number of links
    uid        user ID of the
               owner
    uname      user name of the
               owner
    gid        group ID of the
               owner
    gname      group name of the
               owner
    size       file size
    atime      time of last access
    adate      date of last access
    mtime      time of last data
               modification
    mdate      date of last data
               modification
    ctime      time of last status
               change
    cdate      date of last status
               change
    readable   on or off
    writable   on or off
    executable on or off
</PRE>
   All attributes are integers except for the *name attributes, which are
   string representation of the corresponding *id attributes and *date
   attributes, which are string representation of the corresponding *time
   attributes.  The time for the *time attributes is measured as seconds
   elapsed since 00:00:00 GMT, Jan.  1, 1970.  The flags readable, writable
   and executable indicate whether the running ECLiPSe process has the
   corresponding permissions on the file. Note that the executable permission 
   for Windows may be approximate, because Windows (especially Vista) have a
   different system for dealing with execute permission.

   The meaning of the bits in the mode attribute is as follows:

<P>
<PRE>
 Mode     Meaning
------------------------------------------------
 8'170000 file type
 8'040000 directory
 8'020000 character special
 8'060000 block special
 8'100000 normal file
 8'120000 symbolic link
 8'140000 socket
------------------------------------------------
 8'004000 set user ID on execution
 8'002000 set group ID on execution
------------------------------------------------
 8'000700 owner access
 8'000400 read permission for owner
 8'000200 write permission for owner
------------------------------------------------
 8'000070 group access
 8'000040 read permission for group
 8'000020 write permission for group
------------------------------------------------
 8'000007 other access
 8'000004 read permission for others
 8'000002 write permission for others
 8'000001 execute/search permission for others
</PRE>
   The bit masks can be defined as user arithmetic functors so that the
   code is more readable (see the examples).

<P>

<H3>Modes and Determinism</H3><UL>
<LI>get_file_info(+, -, -) is nondet
<LI>get_file_info(+, +, -) is semidet
</UL>
<H3>Fail Conditions</H3>
Fails if the file File does not exist, or doesn't have the attribute Attr
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>File is not instantiated.
<DT><EM>(5) type error </EM>
<DD>File is neither an atom nor a string.
<DT><EM>(5) type error </EM>
<DD>Attr is instantiated but not to an atom.
<DT><EM>(5) type error </EM>
<DD>Value is instantiated but not to a constant.
</DL>
<H2>Examples</H2>
<PRE>
Success:
   file_type(8'170000).

   directory_flag(8'40000).

   owner_read(8'400).

   is_directory(File) :-
        get_file_info(File, mode, Mode),
        Mode /\ file_type =:= directory_flag.
   readable(File) :-
        get_file_info(File, mode, Mode),
        Mode /\ owner_read =:= owner_read.

   % A file is younger if its time is greater
   is_younger(File1, File2) :-
        get_file_info(File1, mtime) &gt; get_file_info(File2, mtime).

Fail:
   get_file_info(nofile, mode, Mode).
   get_file_info('/', mode, 8'100000).

Error:
   get_file_info(File, ctime, T).                (Error 4).
   get_file_info([file], gid, G).                (Error 5).
   get_file_info(file, 1, X).                    (Error 5).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/opsys/exists-1.html">exists / 1</A>, <A HREF="../../kernel/opsys/delete-1.html">delete / 1</A>, <A HREF="../../kernel/opsys/exec-3.html">exec / 3</A>, <A HREF="../../kernel/opsys/local_time-8.html">local_time / 8</A>, <A HREF="../../kernel/opsys/local_time_string-3.html">local_time_string / 3</A>
</BODY></HTML>
